From 971b2e06f50855708156e4cf9b68b49d91f0877c Mon Sep 17 00:00:00 2001 From: robertl Date: Fri, 24 Jun 2005 19:42:17 +0000 Subject: [PATCH] More Vito improvements. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@1226 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/README | 14 +-- gpsbabel/mingw/mkwintesto.c | 9 +- gpsbabel/msvc/GPSBabel.dsp | 32 +++++- gpsbabel/testo | 4 +- gpsbabel/vitosmt.c | 211 ++++++++++++++++++++++++++++-------- 5 files changed, 204 insertions(+), 66 deletions(-) diff --git a/gpsbabel/README b/gpsbabel/README index bf9149fc5..2380cee33 100644 --- a/gpsbabel/README +++ b/gpsbabel/README @@ -833,16 +833,12 @@ THE FORMATS VitoSMT Vito Navigator II is a Pocket PC GPS application. This format reads - a Vito Navigator II .SMT track file and can work in either waypoint - or track mode. The tzoffset parameter is used to set the UTC offset - of the imput file. + a Vito Navigator II .SMT track file and can work in either waypoint + or track mode. The speed, heading and Dilution of Position data + is written in the notes field. - for example, process a file that was produced in Eastern Daylight - Time (-4h from UTC): - gpsbabel -i vitosmt,tzoffset=-4 -f vitosmt.smt - - A file that was produced in France Daylight Savings time: - gpsbabel -i vitosmt,tzoffset=1 -f paris.smt + Support for writing .SMT tracks is very experimental and may crash + VitoNavigator II on the Pocket PC. DATA FILTERS diff --git a/gpsbabel/mingw/mkwintesto.c b/gpsbabel/mingw/mkwintesto.c index 4a811f59a..661fcb827 100644 --- a/gpsbabel/mingw/mkwintesto.c +++ b/gpsbabel/mingw/mkwintesto.c @@ -244,7 +244,7 @@ int argc, } iPrevLineContinues = f_outputLine(pfTestoOut, acLineOut); if (iPrevLineContinues == 1) f_outputLine(pfTestoOut, ""); - iPrevLineContinues = f_outputLine(pfTestoOut, "IF NOT EXIST %PNAME% ECHO Can't find %PNAME%&& GOTO :EOF"); + iPrevLineContinues = f_outputLine(pfTestoOut, "IF NOT EXIST %PNAME%.EXE ECHO Can't find %PNAME%&& GOTO :EOF"); /* fputs("\r\n"); */ } /* Are we near the top of testo where the program variable is defined? */ @@ -413,6 +413,13 @@ int argc, /* skip forward to the end of the string matched (less one as the loop will add one) */ iThisChar += 8; + } else if (strncmp("${PNAME} ",acLineIn+iThisChar,9) == 0) { + strcpy(acLineOut+iTarget+iThisChar-iStart,"%PNAME% "); + /* one char shorter */ + iTarget--; + /* skip forward to the end of the string matched + (less one as the loop will add one) */ + iThisChar += 8; } else if (acLineIn[iThisChar] == '/') { acLineOut[iTarget+iThisChar-iStart] = '\\'; } else { diff --git a/gpsbabel/msvc/GPSBabel.dsp b/gpsbabel/msvc/GPSBabel.dsp index 74d347e22..9ec071243 100644 --- a/gpsbabel/msvc/GPSBabel.dsp +++ b/gpsbabel/msvc/GPSBabel.dsp @@ -42,7 +42,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /WX /GX /O2 /I "expat" /I "..\coldsync" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "__WIN32__" /D VERSION=\"1.2.1_beta01072004_msvc\" /YX /FD /c +# ADD CPP /nologo /W3 /WX /GX /O2 /I "expat" /I "..\coldsync" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "__WIN32__" /D VERSION=\"1.2.6_beta06232005_msvc\" /YX /FD /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe @@ -66,7 +66,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /W3 /WX /Gm /GX /ZI /Od /I "expat" /I "..\coldsync" /D "WIN32" /D "__WIN32__" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D VERSION=\"1.2.1_beta01072004_msvc\" /FR /YX /FD /GZ /c +# ADD CPP /nologo /W3 /WX /Gm /GX /ZI /Od /I "expat" /I "..\coldsync" /D "WIN32" /D "__WIN32__" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D VERSION=\"1.2.6_beta06232005_msvc\" /FR /YX /FD /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe @@ -303,19 +303,19 @@ SOURCE=..\shapelib\shpopen.c # End Group # Begin Source File -SOURCE=..\arcdist.c +SOURCE=..\an1.c # End Source File # Begin Source File -SOURCE=..\brauniger_iq.c +SOURCE=..\arcdist.c # End Source File # Begin Source File -SOURCE=..\cetus.c +SOURCE=..\brauniger_iq.c # End Source File # Begin Source File -SOURCE=..\vitosmt.c +SOURCE=..\cetus.c # End Source File # Begin Source File @@ -427,6 +427,10 @@ SOURCE=..\lowranceusr.c # End Source File # Begin Source File +SOURCE=..\maggeo.c +# End Source File +# Begin Source File + SOURCE=..\magnav.c # End Source File # Begin Source File @@ -479,6 +483,10 @@ SOURCE=..\palmdoc.c # End Source File # Begin Source File +SOURCE=..\pathaway.c +# End Source File +# Begin Source File + SOURCE=..\pcx.c # End Source File # Begin Source File @@ -535,6 +543,10 @@ SOURCE=..\stackfilter.c # End Source File # Begin Source File +SOURCE=..\tef_xml.c +# End Source File +# Begin Source File + SOURCE=..\text.c # End Source File # Begin Source File @@ -547,6 +559,10 @@ SOURCE=..\tmpro.c # End Source File # Begin Source File +SOURCE=..\tomtom.c +# End Source File +# Begin Source File + SOURCE=..\tpg.c # End Source File # Begin Source File @@ -571,6 +587,10 @@ SOURCE=..\vecs.c # End Source File # Begin Source File +SOURCE=..\vitosmt.c +# End Source File +# Begin Source File + SOURCE=..\vmem.c # End Source File # Begin Source File diff --git a/gpsbabel/testo b/gpsbabel/testo index c778e4ef9..221f3e35c 100755 --- a/gpsbabel/testo +++ b/gpsbabel/testo @@ -711,9 +711,9 @@ compare ${TMPDIR}/pathaway.gpx reference/track/pathaway.gpx # Vito Navigator II .smt tests # rm -f ${TMPDIR}/vitosmt* -${PNAME} -i vitosmt,tzoffset=-4 -f reference/vitosmt.smt -o gpx -F ${TMPDIR}/vitosmt.gpx +${PNAME} -i vitosmt -f reference/vitosmt.smt -o gpx -F ${TMPDIR}/vitosmt.gpx compare ${TMPDIR}/vitosmt.gpx reference/vitosmt.gpx -${PNAME} -t -i vitosmt,tzoffset=-4 -f reference/vitosmt.smt -o gpx -F ${TMPDIR}/vitosmt_t.gpx +${PNAME} -t -i vitosmt -f reference/vitosmt.smt -o gpx -F ${TMPDIR}/vitosmt_t.gpx compare ${TMPDIR}/vitosmt_t.gpx reference/track/vitosmt_t.gpx # diff --git a/gpsbabel/vitosmt.c b/gpsbabel/vitosmt.c index 85bbdf989..9f77dd4c1 100644 --- a/gpsbabel/vitosmt.c +++ b/gpsbabel/vitosmt.c @@ -22,12 +22,18 @@ #include #include #include +#include #define MYNAME "vitosmt" #include "defs.h" -FILE *infile; -static char * arg_tzoffset=NULL; + +FILE *infile =0; +FILE *ofs =0; +gbuint32 count =0; + +#define VITOSMT_HEADER 24 +#define VITOSMT_DATA 64 static unsigned long ReadLong(FILE * f) @@ -41,17 +47,18 @@ ReadLong(FILE * f) static double ReadDouble(FILE * f) { - /* unsigned char result[8] = "\0\0\0\0\0\0\0\0"; */ + unsigned char buffer[8] = "\0\0\0\0\0\0\0\0"; double result=0; - fread(&result, sizeof (result), 1, f); + fread(buffer, sizeof (buffer), 1, f); + le_read64(&result,buffer); return result; } static unsigned char * ReadRecord(FILE * f, - unsigned long size) + size_t size) { unsigned char *result = (unsigned char *) xmalloc(size); @@ -61,11 +68,22 @@ ReadRecord(FILE * f, static void Skip(FILE * f, - unsigned long distance) + size_t distance) { fseek(f, distance, SEEK_CUR); } +void +WriteDouble(void* ptr, double d) +{ + unsigned char result[8]="\0\0\0\0\0\0\0\0"; + + le_read64(result, &d); + memcpy(ptr, result, 8); + + return; +} + static void rd_init(const char *fname) { @@ -81,41 +99,34 @@ rd_deinit(void) static void vitosmt_read(void) { - unsigned short version =0; - unsigned long count =0; - const unsigned long recsize =64; - unsigned short stringlen =0; - route_head *track_head =0; - waypoint *wpt_tmp =0; - double latrad =0; - double lonrad =0; - double elev =0; + gbuint32 version =2; + gbuint32 subversion =1000; + const size_t recsize =VITOSMT_DATA; + route_head *track_head =0; + waypoint *wpt_tmp =0; + double latrad =0; + double lonrad =0; + double elev =0; unsigned char* timestamp =0; - struct tm tmStruct ={0,0,0,0,0,0,0,0,0}; - double seconds =0.0; - double speed =0.0; - double heading =0.0; - double dop =0.0; + struct tm tmStruct ={0,0,0,0,0,0,0,0,0}; + double seconds =0.0; + double speed =0.0; + double heading =0.0; + double dop =0.0; unsigned char* unknown =0; - char shortname[10] ="\0"; - char description[40] ="\0"; - int serial =0; - int iTzoffset =0; - - /* Compute offset between local time zone and time offset argument */ - if (arg_tzoffset) { - iTzoffset = get_tz_offset() - (int)(60*60*atof(arg_tzoffset)); - } + char shortname[10] ="\0"; + char description[40] ="\0"; + int serial =0; /* * 24 bytes header */ - version = ReadLong(infile); /* 2 */ - ReadLong(infile); /* 1000 */ - count = ReadLong(infile); /* 600 */ - ReadLong(infile); /* 0 */ - ReadLong(infile); /* 599 */ - ReadLong(infile); /* 600 */ + version = ReadLong(infile); /* 2 */ + subversion = ReadLong(infile); /* 1000 */ + count = ReadLong(infile); /* total trackpoints */ + ReadLong(infile); /* first trackpoint */ + ReadLong(infile); /* last trackpoint */ + ReadLong(infile); /* total trackpoints */ while (count) { /* @@ -123,7 +134,8 @@ vitosmt_read(void) */ if (feof(infile)||ferror(infile)) { - break; + fatal("%s reading input file. Error was '%s'.\n", + MYNAME, strerror(errno)); } latrad =ReadDouble(infile); /* WGS84 latitude in radians */ @@ -150,12 +162,12 @@ vitosmt_read(void) tmStruct.tm_sec =(int)floor(seconds); tmStruct.tm_isdst =-1; - wpt_tmp->creation_time = mktime(&tmStruct) + iTzoffset; + wpt_tmp->creation_time = mktime(&tmStruct) + get_tz_offset(); wpt_tmp->centiseconds = fmod(100*seconds+0.5,100); snprintf(shortname, sizeof shortname-1 , "WP%04d", ++serial); snprintf(description, sizeof description-1, - "Spd=%.1lf Hdg=%03.0lf DoP=%4.1lf Flg=%02x%02x%02x", + "Spd=%.1lf Hdg=%03.0lf DoP=%.1lf Flg=%02x%02x%02x", speed,heading,dop,unknown[0],unknown[1],unknown[2]); wpt_tmp->shortname = xstrdup(shortname); @@ -191,24 +203,127 @@ vitosmt_read(void) static void wr_init(const char *fname) { - fatal(MYNAME ":Not enough information is known about this format to write it.\n"); + warning(MYNAME ":format is experimental and may crash Vito Navigator II.\n"); + ofs = xfopen(fname, "wb", MYNAME); } -static -arglist_t vitosmt_args[] = { - {"tzoffset", &arg_tzoffset, "Time zone offset of SMT file (hours)", NULL, ARGTYPE_FLOAT }, - {0, 0, 0, 0, 0} -}; +static void +wr_deinit(void) +{ + fclose(ofs); + +} + + +static void +vitosmt_waypt_pr(const waypoint *waypointp) +{ + const size_t recsize =VITOSMT_DATA; + unsigned char workbuffer[VITOSMT_DATA] ="\0"; + size_t position =0; + struct tm* tmstructp =0; + double seconds =0; + double worknum =0; + + ++count; + memset(workbuffer,0,recsize); + + WriteDouble(&workbuffer[position], (M_PI*waypointp->latitude)/180 ); + position += sizeof(double); + WriteDouble(&workbuffer[position], (M_PI*waypointp->longitude)/180 ); + position += sizeof(double); + WriteDouble(&workbuffer[position], waypointp->altitude ); + position += sizeof(double); + + tmstructp = gmtime(&waypointp->creation_time); + seconds = (double) tmstructp->tm_sec + 0.01*waypointp->centiseconds; + + workbuffer[position++] =tmstructp->tm_year-100; + workbuffer[position++] =tmstructp->tm_mon+1; + workbuffer[position++] =tmstructp->tm_mday; + workbuffer[position++] =tmstructp->tm_hour; + workbuffer[position++] =tmstructp->tm_min; + + WriteDouble(&workbuffer[position], seconds ); + position += sizeof(double); + + if (fwrite(workbuffer,recsize,1,ofs)!=1) + { + fatal("%s writing output file. Error was '%s'.\n", + MYNAME, strerror(errno)); + } + +} + +static void +vitosmt_track_hdr(const route_head *rte) +{ +} + +static void +vitosmt_track_tlr(const route_head *rte) +{ +} + +void +vitosmt_write(void) +{ + time_t now = 0; + const size_t recsize =VITOSMT_HEADER; + const gbuint32 version =2; + const gbuint32 subversion =1000; + unsigned char workbuffer[VITOSMT_HEADER] ="\0"; + size_t position =0; + + now = current_time(); + count = 0; + position = 0; + + /* leave a spacer for the header */ + memset(workbuffer,0,recsize); + if (fwrite(workbuffer,recsize,1,ofs)!=1) + { + fatal("%s writing output file. Error was '%s'.\n", + MYNAME, strerror(errno)); + } + + /* dump waypoints and tracks */ + waypt_disp_all(vitosmt_waypt_pr); + track_disp_all(vitosmt_track_hdr, vitosmt_track_tlr, vitosmt_waypt_pr); + + /* write the complete the header */ + le_write32(&workbuffer[position],version); + position += sizeof(gbuint32); + le_write32(&workbuffer[position],subversion); + position += sizeof(gbuint32); + le_write32(&workbuffer[position],count); + position += sizeof(gbuint32); + le_write32(&workbuffer[position],0); + position += sizeof(gbuint32); + le_write32(&workbuffer[position],count-1); + position += sizeof(gbuint32); + le_write32(&workbuffer[position],count); + position += sizeof(gbuint32); + + rewind(ofs); + if (fwrite(workbuffer,recsize,1,ofs)!=1) + { + fatal("%s writing output file. Error was '%s'.\n", + MYNAME, strerror(errno)); + } + + +} ff_vecs_t vitosmt_vecs = { ff_type_file, - { ff_cap_read, ff_cap_read, ff_cap_none}, + { ff_cap_read | ff_cap_write, ff_cap_read | ff_cap_write, ff_cap_none}, rd_init, wr_init, rd_deinit, - NULL, + wr_deinit, vitosmt_read, - NULL, + vitosmt_write, NULL, - vitosmt_args + NULL }; -- 2.30.2